package com.fly.push.flux.hight;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Flux;

@RestController
public class SinksSseConsumerController
{
    @Autowired
    SinksSsePublisherService ssePublisherService;
    
    @GetMapping("/sinks/stream")
    public Flux<ServerSentEvent<String>> consumeSse()
    {
        return ssePublisherService.getMessages().map(message -> ServerSentEvent.<String> builder().data(message).build());
    }
}